package cn.iocoder.yudao.im.task;

import cn.iocoder.yudao.im.domain.AiChatHistory;
import cn.iocoder.yudao.im.mapper.AiChatHistoryMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author admin
 */
@Component
@Slf4j
public class HistoryTask {

    @Resource
    AiChatHistoryMapper aiChatHistoryMapper;

    @Scheduled(cron = "0 0 1 * * ?")
    public void cron() {
        LocalDateTime sevenDaysAgo = LocalDateTime.now().minusDays(30);
        AiChatHistory aiChatHistory = new AiChatHistory();
        aiChatHistory.setState(1);
        int update = aiChatHistoryMapper.update(aiChatHistory, new LambdaQueryWrapper<AiChatHistory>().lt(AiChatHistory::getCreateTime, sevenDaysAgo).eq(AiChatHistory::getState, 0));
        log.info("<<<<<开始清除30天前的Ai聊天记录>>>>> 总条数：{} >>>>>每天一点执行一次！", update);
    }
}

